package router.base.client;

import java.util.concurrent.ConcurrentLinkedQueue;

import router.base.linker.CSLinker;
import router.base.router.RouterException;
import router.message.Message;

/**ZerdNet client designed to buffer incoming messages until the user reads them.
 * @author Zerdligham
 *
 */
public class PollClient extends Client {
	private ConcurrentLinkedQueue<Message> messages = new ConcurrentLinkedQueue<>();
	
	/**Creates a new client, which will buffer incoming messages until the user reads them.
	 * @param name
	 * @param linker
	 * @throws RouterException 
	 */
	public PollClient(CSLinker linker) {
		super(linker);
	}

	@Override
	public void offer(Message msg) {
		messages.offer(msg);
	}
	
	/**Read the oldest message received. The message is suppressed from the buffer.
	 * @return the oldest message received, or null if there is no message to receive
	 */
	public Message poll() {
		return messages.poll();
	}
	

}
